package ${package.Controller};

import com.x.springboot.common.CommonResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.*;
import com.github.pagehelper.PageInfo;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import java.util.List;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@RestController
<#--@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")-->
@RequestMapping("/${entity?uncap_first}")
@Api(tags = "${table.comment!}API")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @ApiOperation(value = "新增", httpMethod = "POST")
    @PostMapping(value = "/create")
    public CommonResult create(@RequestBody ${entity} ${entity?uncap_first}) {
        ${table.serviceName?uncap_first}.create(${entity?uncap_first});
        return CommonResult.success();
    }

    @ApiOperation(value = "根据ID删除", httpMethod = "POST")
    @PostMapping(value = "/delete")
    public CommonResult deleteBatch(@RequestBody Integer id) {
        ${table.serviceName?uncap_first}.delete(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "根据ID集合批量删除", httpMethod = "POST")
    @PostMapping(value = "/deleteBatch")
    public CommonResult deleteBatch(@RequestBody List<Integer> ids) {
        ${table.serviceName?uncap_first}.deleteBatch(ids);
        return CommonResult.success();
    }

    @ApiOperation(value = "修改", httpMethod = "POST")
    @PostMapping(value = "/update")
    public CommonResult update(@RequestBody ${entity} ${entity?uncap_first}) {
        ${table.serviceName?uncap_first}.update(${entity?uncap_first});
        return CommonResult.success();
    }

    @ApiOperation(value = "根据主键ID查询", httpMethod = "GET")
    @GetMapping(value = "/get")
    public CommonResult<${entity}> get(@ApiParam(value="id") @RequestParam(value = "id",required = true) Integer id) {
        return CommonResult.success(${table.serviceName?uncap_first}.get(id));
    }

    @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    @ApiImplicitParam(name = "pageSize", value = "每页显示的条数", required = true, dataType = "int")})
    @ApiOperation(value = "分页查询", httpMethod = "GET")
    @GetMapping(value = "/query")
    public CommonResult<PageInfo<#noparse><</#noparse>${entity}>> query(${entity} ${entity?uncap_first},int pageNum,int pageSize) {
        PageInfo<#noparse><</#noparse>${entity}> pageInfo = ${table.serviceName?uncap_first}.query(${entity?uncap_first},pageNum,pageSize);
        return CommonResult.success(pageInfo);
    }

}